# !/usr/bin/env python
# -*- coding: utf-8 -*-
# @File  : GBDT-泰坦尼克号预测.py
# @Author: dongguangwen
# @Date  : 2025-02-08 15:39
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.metrics import classification_report


data = pd.read_csv('./data/titanic/train.csv')
# print(data.head())
# print(data.info())

x = data[['Pclass', 'Sex', 'Age']].copy()
y = data['Survived'].copy()
# print(x.head(10))

x['Age'] = x['Age'].fillna(x['Age'].mean())
# print(x.head(10))

x = pd.get_dummies(x)
# print(x.head(10))

x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=22)

model = GradientBoostingClassifier()
model.fit(x_train, y_train)

print(model.score(x_test, y_test))
y_pred = model.predict(x_test)
print(classification_report(y_test, y_pred))


"""
0.7541899441340782
              precision    recall  f1-score   support

           0       0.79      0.82      0.80       110
           1       0.69      0.65      0.67        69

    accuracy                           0.75       179
   macro avg       0.74      0.74      0.74       179
weighted avg       0.75      0.75      0.75       179
"""
